﻿using System;
using System.Collections.Generic;
using System.Text;
using TSVNAddin.TSVN;
using TSVNAddin.SVN;
using TSVNAddin.Config;
using EnvDTE80;

namespace TSVNAddin.Core
{
	public class CommandFactory
	{
		public virtual CommandDictionary CreateCommands(DTE2 applicationObject)
		{
			SolutionAdapter dteAdapter = new SolutionAdapter(applicationObject);

			TortoiseProcExecutor tortoiseProcExecutor = new TortoiseProcExecutor(new ProcessStarter(), new ConfigStorage(new XmlFileStorage()));
			Repository repository = new Repository(dteAdapter, new SVNClientAdapter());

			CommandDictionary commands = new CommandDictionary();
			commands.Add(CommandType.Diff, new DiffCommand(new ActiveDocumentAdapter(applicationObject), tortoiseProcExecutor, repository));
			commands.Add(CommandType.Update, new UpdateCommand(tortoiseProcExecutor, repository));
			commands.Add(CommandType.Commit, new CommitCommand(tortoiseProcExecutor, repository));
			commands.Add(CommandType.ShowLog, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Log));
			commands.Add(CommandType.RepoBrowser, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Repobrowser));
			commands.Add(CommandType.ShowChanges, new ShowChangesCommand(tortoiseProcExecutor, repository));
			commands.Add(CommandType.RevisionGraph, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Revisiongraph));
			commands.Add(CommandType.UpdateToRevision, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Update, TortoiseProcArgumentType.rev));
			commands.Add(CommandType.Rename, new NotSupportedCommand());
			commands.Add(CommandType.Delete, new NotSupportedCommand());
			commands.Add(CommandType.Revert, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Revert));
			commands.Add(CommandType.GetLock, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Lock));
			commands.Add(CommandType.ReleaseLock, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Unlock));
			commands.Add(CommandType.BranchTag, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Copy));
			commands.Add(CommandType.Switch, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Switch));
			commands.Add(CommandType.Merge, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Merge));
			commands.Add(CommandType.Blame, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Blame));
			commands.Add(CommandType.CreatePatch, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.CreatePatch));
			commands.Add(CommandType.ApplyPatch, new NotSupportedCommand());
			commands.Add(CommandType.Properties, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Properties));
			commands.Add(CommandType.Settings, new GenericPathCommand(tortoiseProcExecutor, repository, TortoiseProcCommandType.Settings));

			commands.Add(CommandType.DiskBrowser, new NotSupportedCommand());
			commands.Add(CommandType.AddSolutionToSubversion, new NotSupportedCommand());
			commands.Add(CommandType.GetSolutionFromSubversion, new NotSupportedCommand());
			commands.Add(CommandType.SetWorkingCopyRoot, new NotSupportedCommand());
			commands.Add(CommandType.CleanupWorkingCopy, new NotSupportedCommand());

			commands.Add(CommandType.AboutTortoiseSVNAddin, new NotSupportedCommand());
			commands.Add(CommandType.AboutTortoiseSVN, new AboutTortoiseSVNCommand(tortoiseProcExecutor));

			return commands;
		}
	}
}
